using System;
using NUnit.Framework;
using MathParser;

namespace UnitTest
{
    [TestFixture]
    public class TestUnit
    {
        [Test]
        public void TestAST()
        {
            Parser parser = new Parser();
            Parser ast = parser.Parse("2+3*4");

            DumpAST(ast, 0);
        }


        private void DumpAST(Parser node, int i)
        {
            if (node != null)
            {
                Console.WriteLine("{0}{1} / {2}", "".PadLeft(i, ' '), node.Expression, node.OpTyp);

                DumpAST(node.ChildLeft, i++);
                DumpAST(node.ChildRight, i++);
            }

        }


        [Test]
        public void Zusammenfassen() // Addition
        {
            Parser parser = new Parser();
            parser.Parse("3*x+4*x");
            string result = parser.JoinForIntegralDifferentialCalculation(true);
            Assert.AreEqual("7*x", result);
        }
        [Test]
        public void Zusammenfassen1() // Subtraktion
        {
            Parser parser = new Parser();
            parser.Parse("3*x-4*x");
            string result = parser.JoinForIntegralDifferentialCalculation(true);
            Assert.AreEqual("-1*x", result);
        }
        [Test]
        public void Zusammenfassen2() // Multiplikation
        {
            Parser parser = new Parser();
            parser.Parse("(x^2-2*x^2)*(4*x+8*x)");
            string result = parser.JoinForIntegralDifferentialCalculation(true);
            Assert.AreEqual("(-1*x^2)*12*x", result);
        }
        [Test]
        public void Zusammenfassen3() // Division
        {
            Parser parser = new Parser();
            parser.Parse("1/(3*x+4*x)");
            string result = parser.JoinForIntegralDifferentialCalculation(true);
            Assert.AreEqual("1/(7*x)", result);
        }
        [Test]
        public void Zusammenfassen3a() // Division
        {
            Parser parser = new Parser();
            parser.Parse("(3*x+6*x)/(3*x+4*x)");
            string result = parser.JoinForIntegralDifferentialCalculation(true);
            Assert.AreEqual("(9*x)/(7*x)", result);
        }
        [Test]
        public void Zusammenfassen4() // Potenzieren
        {
            Parser parser = new Parser();
            parser.Parse("(3*x+7*x)^(2*x)");
            string result = parser.JoinForIntegralDifferentialCalculation(true);
            Assert.AreEqual("(10*x)^(2*x)", result);
        }
        [Test]
        public void Differenziation() // ln
        {
            Parser parser = new Parser();
            parser.Parse("ln(3*x)");
            string result = parser.Differenziere();
            Assert.AreEqual("1/(3*x)*3", result);
        }
        [Test]
        public void Differenziation2() // ln
        {
            Parser parser = new Parser();
            parser.Parse("ln(3/x)");
            string result = parser.Differenziere();
            Assert.AreEqual("1/(3/x)*(-3)/x^2", result);
        }
        public void Differenziation3() // e^x
        {
            Parser parser = new Parser();
            parser.Parse("e^(3*x)");
            string result = parser.Differenziere();
            Assert.AreEqual("3*e^(3*x)", result);
        }
        [Test]
        public void Integration() 
        {
            Parser parser = new Parser();
            parser.Parse("7*x^3");
            string result = parser.Integriere();
            Assert.AreEqual("1,75*x^4", result);
        }
    }
}
